//
//  LJJLoginViewController.m
//  shopTest
//
//  Created by 梁佳佳 on 2016/11/15.
//  Copyright © 2016年 梁佳佳. All rights reserved.
//

#import "LJJLoginViewController.h"
#import "LJJLoginView.h"
#import "LJJThirdLoginView.h"

@interface LJJLoginViewController ()

@property (strong, nonatomic) LJJLoginView *loginView;    /** 登录 **/
@property (strong, nonatomic) LJJThirdLoginView *thirdLoginView;    /** 第三方登录 **/

@end

@implementation LJJLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"登录";
    self.edgesForExtendedLayout = 0;
    [self configUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
#pragma mark -
#pragma mark - method
- (void)configUI
{
    [self.view addSubview:self.loginView];
    [self.view addSubview:self.thirdLoginView];
    __weak typeof (self) weakSelf = self;
    [_loginView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(weakSelf.view);
        make.height.equalTo(@200);
    }];
    [_thirdLoginView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.loginView.mas_bottom);
        make.left.right.equalTo(weakSelf.view);
        make.height.equalTo(@85);
    }];
}
- (void)loginMethod:(NSDictionary *)dic{
    //    http://123.57.141.249:8080/beautalk/appMember/appLogin.do
    //    登陆名:LoginName
    //    密码 :Lpassword
    [self getData:@"appMember/appLogin.do" param:dic success:^(id responseObject) {
        //用户不存在
        //密码错误
        //登陆成功
        LJJLog(@"responseObject : %@",responseObject);
        if ([responseObject[@"ErrorMessage"] isEqualToString:@"登陆成功"]) {
            [self showTostMessage:@"登录成功"];
            [[NSUserDefaults standardUserDefaults] setObject:responseObject forKey:@"ISLOGIN"];
            [self performSelector:@selector(popMyViewController) withObject:nil afterDelay:1.0];
        }else if ([responseObject[@"ErrorMessage"] isEqualToString:@"密码错误"]){
            [self showTostMessage:@"密码错误"];
        }else if ([responseObject[@"ErrorMessage"] isEqualToString:@"用户不存在"]){
            [self showTostMessage:@"用户不存在"];
        }else{
            [self showTostMessage:@"登录失败"];
        }
    } error:^(NSError *error) {
        LJJLog(@"error : %@",error);
    }];
}
- (void)popMyViewController
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
#pragma mark -
#pragma mark - lazy method
- (LJJLoginView *)loginView
{
    if (!_loginView) {
        _loginView = [[LJJLoginView alloc] init];
        __weak typeof(self) weakSelf = self;
        _loginView.loginBlock = ^(NSDictionary *dic){
            [weakSelf loginMethod:dic];
        };
    }
    return _loginView;
}
- (LJJThirdLoginView *)thirdLoginView
{
    if (!_thirdLoginView) {
        _thirdLoginView = [[LJJThirdLoginView alloc] init];
    }
    return _thirdLoginView;
}

@end
